package server

import (
	"log"
	pbCity "wire/api/city"
	pbUser "wire/api/user"
	"wire/internal/data"
	"wire/internal/server/middleware"

	"gitee.com/go-mod/framework/grpc"
	"gitee.com/go-mod/framework/http"
	"github.com/gin-gonic/gin"
	"github.com/google/wire"
)

var ProviderSet = wire.NewSet(NewUserHTTPServer, NewCityHTTPServer, NewHTTPServer, NewUserGRPCServer, NewCityGRPCServer, NewGRPCServer)

func NewHTTPServer(user *UserHTTPServer, city *CityHTTPServer, data *data.Data) *http.Server {
	server := http.NewServer()
	server.Eng.Use(gin.Logger())
	server.Eng.Use(middleware.Recovery())

	api := server.Eng.Group("/v1")
	api.Use(middleware.Init(data))
	{
		api.GET("/user/get", user.Get)
		api.GET("/user/list", user.List)

		api.GET("/city/get", city.Get)
		api.GET("/city/all", city.All)
	}
	return server
}

func NewGRPCServer(user *UserGRPCServer, city *CityGRPCServer) *grpc.Server {
	server := grpc.NewServer()
	pbUser.RegisterUserServer(server.Server, user)
	pbCity.RegisterCityServer(server.Server, city)

	log.Println("Register User GRPCServer")
	log.Println("Register City GRPCServer")
	return server
}
